<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Ticketuse extends Model
{
    //

    public function getTicketClassroom($time = null, $schoolId = null, $name = null)
    {
//       $time=array_values($time);

        return $this->alias('t')
            ->join('student s', 's.id=t.student_id')
            ->join('course c','c.id=t.course_id')
            ->join('classroom cr','cr.id=c.classroom_id')
            ->where('t.start_time', $time['start_time'])
            ->where('t.end_time', $time['end_time'])
            ->when($schoolId,function ($q) use($schoolId){
                $q->where('t.school_id',$schoolId);
            })
            ->field('cr.id,cr.school_id,cr.name,cr.number,cr.color,c.sort')
            ->group('cr.id')
            ->order('cr.id','desc')
            ->select()
            ->toArray();
    }

    public function getUsedTicket($time, $where = null, $name = null,$id=null)
    {
        return $this->alias('t')
            ->join('invoice_details ivd', 't.invoice_details_id=ivd.id')
            ->join('invoice i', 'i.id=ivd.invoice_id')
            ->join('student s', 't.student_id=s.id')
            ->when($id,function ($q)use($id){
                $q->where('s.id',$id);
            })
            ->where('t.id','<',0)
            ->field('t.*,s.name')
            ->select()->toArray();
    }
}
